package factory.simple;

/**
 * Remarks:
 * Class name :Consumer
 * Date :2023/2/16 23:22
 * Author:杨俊源
 */
public class Consumer {
    public static void main(String[] args) {
        //传统模式
        Car car1 = new WuLing();
        Car car2 = new Tesla();

        car1.name();
        car2.name();

        //工厂模式
        Car car = CarFactory.getCar("五菱");
        car.name();

    }
}

interface Car {
    void name();
}

class WuLing implements Car {
    @Override
    public void name() {
        System.out.println("五菱宏光");
    }
}

class Tesla implements Car {

    @Override
    public void name() {
        System.out.println("特斯拉");
    }
}

class Dazhong implements Car {
    @Override
    public void name() {
        System.out.println("大众");
    }
}

class CarFactory {
    //方法一
    public static Car getCar(String car){
        if (car.equals("五菱")){
            return new WuLing();
        }else if(car.equals("特斯拉")){
            return new Tesla();
        }else {
            return null;
        }
    }
}

